<style>
    .show{display: inherit}
    .hide{display: none}
    .layui-table-cell {line-height:22px;padding:1px 3px; }/*overflow: inherit;超表格显示*/
	.laytable-cell-1-0-22{white-space:inherit}
	.layui-table-cell{padding:1px 2px;text-align:center;line-height:19px;}
	th span{white-space:normal;}
	.layui-table img{max-height:50px;}
    .redclass{color:#CC0000;font-weight:bold;}
	.people_add{background-color:#EEEEDD !important;}
	.waring{background-color:#9BBB58 !important;}
	.warning3{background-color:#FF9900 !important;}
	.quintityChanged,.changedBg{background-color:#E3FEE2;}
	.quintityToBig{background-color:#FFCC00;}
	.layui-form-pane .layui-form-label{width:auto;}
	.fixed-bar-tr-header{top:163px;}
	.tools-header{top:110px;padding:10px 15px;}
	.underline{text-decoration:underline;}
	.remarkLabel span{text-decoration:underline;cursor:pointer}
	.laytable-cell-1-0-19{color:#006633;}
	.laytable-cell-1-0-26{padding:10px 2px;}
	.createBillTemp select{width:180px;height:30px;}
</style>
<div class="fixed-bar" style="clear:both;">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('',['status' => $status,'process_stage' => $process_stage])}" method="get" id="hisi-table-search">
    	<input type="hidden" name="process_stage" value="{:$process_stage}" />
        <div class="layui-form-item">
        	<div class="layui-inline">
               <label class="layui-form-label ">入仓日期</label>
               <div class="layui-input-inline">
                   <input type="text" name="instock_date_range" readonly="" value="{$overtime_range}" id="instock_date_range" lay-verify="" placeholder="入仓日期" class="layui-input">
               </div>
            </div>
        	<div class="layui-inline">
                <label class="layui-form-label ">完成日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择完成日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">工序</label>
                <div class="layui-input-inline" style="width:130px;">
                    <input type="text" name="process_name" lay-verify="" placeholder="工序名称" class="layui-input">
                </div>
            </div>
        	<div class="layui-inline">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline" style="width:130px;">
                    <input type="text" name="user_name" lay-verify="" placeholder="输入姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">员工编号</label>
                <div class="layui-input-inline" style="width:130px;">
                    <input type="text" name="user_number" lay-verify="" placeholder="员工编号" class="layui-input" >
                </div>
            </div>
            
            <div class="layui-inline">
                <label class="layui-form-label">组别</label>
                <div class="layui-input-inline">
                    <input type="text" name="group_name" lay-verify="" placeholder="组别名称" class="layui-input">
                </div>
            </div>

            <div class="layui-inline removeStat">
                <label class="layui-form-label">SKU</label>
                <div class="layui-input-inline">
                    <input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">件数差异</label>
                <div class="layui-input-inline" style="width:100px;">
                	{:Form::select('diff_count_logic', 'gt', ['gt'=>'大于', 'eq'=>'等于','lt'=>'小于'], '', '')}
                </div>
                <div class="layui-input-inline" style="width:90px;">
                	<input type="text" name="diff_count" style="width:66px;display:inline-block" lay-verify="" placeholder=" 件数" class="layui-input"> 件
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结算单价</label>
                <div class="layui-input-inline" style="width:140px;">
                    <input type="text" name="process_price" lay-verify="" placeholder="输入单价" class="layui-input">
                </div>
            </div>
            
            <div class="layui-inline">
                <label class="layui-form-label">所属工厂</label>
                <div class="layui-input-inline">
                    {:Form::select('factory_id', '', $factoryKV, '', '')}
                </div>
            </div>
            
            
            <span style="display:none;">
            <button type="button" class="layui-btn layui-btn-primary" id="test10">导入金鹏工价</button>
            <button type="button" class="layui-btn layui-btn-primary" id="test11">导入</button>
            </span>
            <div class="layui-inline">
                <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                <button type="button" class="layui-btn layui-btn-primary hisi-export show">导出</button>
            </div>
        </div>
    </form>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="clear:both;">
    <ul class="layui-tab-title" id="vue_tab_content">
        <li class="layui-this"><a onclick="statCli(1)" href="#">等待审核（<span class="red bold stat-num-1">{{ statData_1 }}</span>条）</a></li>
        <li><a onclick="statCli(2)" href="#">对帐中（<span class="red bold stat-num-2">{{ statData_2 }}</span>条）</a></li>
        <li><a onclick="statCli(3)" href="#">复合对帐（<span class="red bold stat-num-2 reCheckCount"></span>条）</a></li>
        <li><a onclick="statCli(4)" href="#">复合对帐明细</a></li>
        <li style="float:right;width:510px;margin-bottom:3px;">
			<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="test12">导入成本报损数</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="test13">导入</button><a style="display:inline-block" href="__STATIC__/demo/brokeOrderDemo.xlsx" target="_blank" title="点击下载导入的xls模板"><i class="layui-icon">&#xe62d;</i>报损模板</a>&nbsp;&nbsp;
            
        	<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="test8">选择文件导入工价</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="test9">导入</button>
            <a style="display:inline-block" href="__STATIC__/demo/tail-process-demo.xls" target="_blank" title="点击下载导入的xls模板"><i class="layui-icon">&#xe62d;</i>xls导入模板</a></li>        
    </ul>
    
</div>
<table id="dataTable" lay-filter="demoEvent"></table>



{include file="system@block/layui" /}

<script type="text/html" id="skuTpl">
    <span class="copy-item">{{ d.client_ordernum }}</span> <br>
    <span class="copy-item">{{ d.sku }}</span>
</script>

<script type="text/html" id="usernameTpl">
	<input type="hidden" name="creater" id="process_data_{{ d.id }}" value="{{ d.creater}}" />
    <span class="copy-item">{{ d.user_name }}</span> <br>
    <span class="copy-item">{{ d.user_number }}</span>
</script>
<script type="text/html" id="picTpl">
    <span class="lay-pic-container" src="{{d.pic_res}}">
        <!--<img src="{{d.pic_res}}" class="lay-pic">-->
    </span>
</script>
<script type="text/html" id="caiChuangTypeTpl">
    {{# if (d.caichuang_type=='1') { }}
    手工裁剪
    {{# } else { }}
    电脑裁剪
    {{# } }}
</script>
<script type="text/html" id="totQuintityTpl">
    {{ d.tot_quintity }}
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
	<div style="text-align:left;line-height:25px;">
    <a href="javascript:void(0)" data-json='{{d.process_name_json}}' data-id="{{ d.order_id }}" data-url="{:url('doEditStatementsProcessPrice')}?order_id={{ d.order_id }}"
	ordernum="{{d.client_ordernum}}" class="layui-btn layui-bg-orange layui-btn-xs edit-processPrice">改单价</a>
	<a href="javascript:void(0)" style="display:none"  data-id="{{ d.order_id }}" data-url="{:url('doEditStatementsProcessPrice')}?order_id={{ d.order_id }}"
	ordernum="{{d.client_ordernum}}" class="layui-btn layui-btn-danger layui-btn-xs del-processPrice" lay-event="delete">删除该条</a>
	<a href="{:url('sewStatements')}?user_number={{ d.user_number }}&order_id={{ d.order_id }}&process_name={{ d.process_name }}&action=getbilldetails&status={{d.action_status}}" title="{{ d.user_name }}-{{d.client_ordernum}}扫菲明细"
   hisi-data="{width: '80%', height: '80%'}" class="hisi-iframe layui-btn layui-btn-xs">扫菲明细</a>
   <br />
   <a href="javascript:void(0)" data-json='{{d.process_name_json}}' data-processname="{{d.process_name}}" data-count="{{d.tot_quintity}}" data-username="{{d.user_name}}" data-id="{{ d.id}}" data-url="{:url('doEditStatementsProcessPrice')}?order_id={{ d.order_id }}" data-usernumber="{{d.user_number}}"	ordernum="{{d.client_ordernum}}" class="layui-btn layui-bg-blue layui-btn-xs edit-paycount">增减结算数</a>
   <a href="javascript:void(0)" data-json='{{d.process_name_json}}'  data-processname="{{d.process_name}}" data-count="{{d.tot_quintity}}" data-username="{{d.user_name}}" data-id="{{ d.id}}" 
    data-usernumber="{{d.user_number}}"	ordernum="{{d.client_ordernum}}"  data-orderid="{{ d.order_id }}" data-url="{:url('statementsCheck')}?action=setBrokeAndNote&order_id={{ d.order_id }}"
	ordernum="{{d.client_ordernum}}" class="layui-btn layui-bg-red layui-btn-xs show-setBrokeAndNote">报损</a>
	<a href="javascript:void(0)" data-json='{{d.process_name_json}}'  data-processname="{{d.process_name}}" data-count="{{d.tot_quintity}}" data-username="{{d.user_name}}" data-id="{{ d.id}}" 
    data-usernumber="{{d.user_number}}"	ordernum="{{d.client_ordernum}}"  data-orderid="{{ d.order_id }}" data-url="{:url('statementsCheck')}?action=setBrokeAndNote&order_id={{ d.order_id }}"
	 class="layui-btn layui-bg-blue layui-btn-xs show-setNoteTpl">备注</a>
	</div>
</script>

<script type="text/html" id="processCountTpl">
 	{{# 
	var classval= d.count_diff > 10  ? "warning warning2" :''; 
	}}
	<span class="{{classval}}">
	<a href="{:url('sewStatements')}?user_number={{ d.user_number }}&order_id={{ d.order_id }}&process_name={{ d.process_name }}&action=getbilldetails&status={{d.action_status}}&show_data=process_data"
	 title="{{ d.client_ordernum}}-{{d.process_name}}-加工明细"
   hisi-data="{width: '80%', height: '80%'}" class="underline hisi-iframe">{{d.process_count}}</a></span>
</script>

<script type="text/html" id="pay_quantity_tpl">
	{{# 
	var classval= d.count_diff < 0  ? "warning" :''; 
	}}
	<span ><!--class="{{classval}}"-->
	<a href="{:url('sewStatements')}?user_number={{ d.user_number }}&order_id={{ d.order_id }}&process_name={{ d.process_name }}&action=getbilldetails&status={{d.action_status}}" title="{{ d.user_name}}-{{d.process_name}}-结算数量修改"
   hisi-data="{width: '80%', height: '80%'}" class="underline hisi-iframe">{{d.tot_quintity}}</a></span>
</script>

<script type="text/html" id="countDiffTpl">
	{{# 
	var classval= Number(d.count_diff) < 0  ? "warning" :'';
	var classval= d.count_diff >= 1  ? "warning2" : classval; 
	}}
	<span class="{{classval}}">{{d.count_diff}}</span>
</script>

<script type="text/html" id="brokeDiffTpl">
	{{# 
	var classval= Number(d.broke_diff) < 0  ? '' :'';
	var classval= d.broke_diff >= 1  ? "warning2" : classval; 
	}}
	<span class="{{classval}}">{{d.broke_diff}}</span>
</script>
    
<script type="text/html" id="recheckActionTpl">
    <a href="{:url('sewStatements')}?user_number={{ d.user_number }}&month={{d.month}}&action=salaryDetailList&show_data=salary_data" title="{{ d.user_name }}{{d.month}}月账单明细" hisi-data="{width: '80%', height: '80%'}" class="hisi-iframe layui-btn layui-btn-xs">帐单明细</a>
</script>
<script type="text/html" id="toolbar">
	<span style="float:left" id="totaldata_tag">
		&nbsp;&nbsp;备注：
		<strong>件数差异</strong>：累计结算 <strong> 与 </strong> 入仓+入库数-占用出库的差异 ，<span style="color:#9BBB58">绿色</span>：累计结算【大于】入仓数，<span style="color:#FF9900">橙色</span>：累计结算【小于】入仓数
		<span title="差异原因可能：缺少入仓/缺少入库/未走系统占用它库/未入报损数/漏扫菲票">&nbsp; 差异原因？ </span>
	 </span>
    <div class="layui-btn-group fr">
		<span class="office_operate">
        <a data-href="{:url('statementsCheck')}?process_stage=1&status=1" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">审核</a>&nbsp;
		</span>
		<span class="finance_operate" style="display:none">
			<a data-href="{:url('callbackBills')}?process_stage=1&status=0" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">驳回</a>&nbsp;&nbsp;
		</span>
		<span class="other_operate">
			<a  href="{:url('editStatements')}?process_stage={:$process_stage}" title="手动增加的加工单" hisi-data="{width: '1200px', height: '86%'}"
			 class="hisi-iframe layui-btn layui-btn-sm layui-btn-primary">增加加工单</a>&nbsp;
			 <a  href="javascript:void(0);" title="设置工资月份"  class="layui-btn layui-btn-sm layui-btn-primary createBillList">设置工资月份</a>&nbsp;
		</span>
        <span class="office_operate">
        	<a data-href="{:url('statementsCheck')}?action=changeDiffCount" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">批量处理差异</a>&nbsp;
		</span>
		<span class="finance_operate" style="display:none">
		<a data-href="{:url('setStatementsSettle')}?process_stage=1&status=2" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">生成账单</a>&nbsp;&nbsp;
		</span>
		<span class="recheck_operate" style="display:none">
			<a data-href="{:url('setStatementsSettle')}?status=2&pay_state=1" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">设置已复核</a>&nbsp;
			<a data-href="{:url('setStatementsSettle')}?status=2&pay_state=2" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">设置已结算</a>&nbsp;&nbsp;
			<a data-href="{:url('setStatementsSettle')}?status=2&pay_state=3" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">设置待复核</a>&nbsp;
		</span>
    </div>
</script>
<div id="changePayCountTpl" class="hide">
    <form class="layui-form" action="{:url()}?action=addProcessCount" method="post" id="editForm">
     <div class="layui-form-item pt20 pl20">
        <div><div class="layui-inline">
			<label class="layui-form-label">增减数量</label>
			<div class="layui-input-inline">
				<input type="text" name="add_pay_count" lay-verify="number" placeholder="增减数量(负数为减去)" class="layui-input add_pay_count">
			</div>
		</div></div>
        <div style="margin-left:30px;margin-top:2px;margin-bottom:10px;margin-left:90px;" class="remarkLabel">
        	<label> <input type="checkbox" name="same_process_change" tabindex="1000" value="all" lay-ignore > 该订单其它人员(<strong>{{d.process_name}}</strong>)工序的数量同样增减；</label>
      	 	<label style="display:none"> <input type="checkbox" name="count_pay_total" tabindex="1000" value="all" lay-ignore > 结算数量为(<strong>{{d.pay_total}}</strong>)的其它人员的工序同样增减；</label>
        </div>
        {:FormExt::textarea('增减数备注', 'check_remark', '', '增减数量备注', '','','style="width:100%;min-height:50px;"')}
        <div style="margin-left:30px;margin-top:-5px;margin-bottom:14px;" class="remarkLabel">常用备注:
         	<span onclick="setRemark(this)">报损数</span> &nbsp;<span onclick="setRemark(this)">入仓差异</span> &nbsp;
            <label><input type="checkbox" name="remarkAll" value="all" lay-ignore  checked>备注引用到其它人员及工序</label>
        </div>
        <div class="layui-inline">
			<label class="layui-form-label">员工编号</label>
			<div class="layui-input-inline">
				<input type="text" name="user_number" value="{{d.user_number}}" lay-verify="required" placeholder="员工编号" class="layui-input">
			</div>
		</div>
        <div class="layui-inline">
			<label class="layui-form-label">员工姓名</label>
			<div class="layui-input-inline">
				<input type="text" name="user_name" value="" placeholder="员工姓名(可不填)" class="layui-input">
			</div>
		</div>
        <div align="center">
        	<input type="hidden" class="field-id" name="process_name" value="{{d.process_name}}">
        	<input type="hidden" class="field-id" name="user_process_total" value="{{d.pay_total}}">
            <input type="hidden" class="field-id" name="id" value="{{d.id}}">
            <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: false, callback:callbackRefershQuintity}">提交保存</button>
            <a href="javascript:layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
        </div>
     </div>
    </form>
</div>

<div id="defectiveTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
    	
		{{#  for(var i in d.list){ }}
		<div class="layui-inline">
			<label class="layui-form-label">{{ d.list[i].process_name }}</label>
			<div class="layui-input-inline">
            	<input type="hidden" name="process_name[]" value="{{ d.list[i].process_name }}" />
                <input type="hidden" name="old_process_price[]" value="{{ d.list[i].process_price }}" />
				<input type="text" name="process_price[]" value="{{ d.list[i].process_price }}" lay-verify="number|required" placeholder="输入单价" class="layui-input process_price_input">
			</div>
		</div>
		{{#  } }}
		<div style="color:#CCCCCC;font-size:12px;margin-bottom:2px;">提示：按【Tab】键可切换到下一行价格</div>
		<input type="hidden" name="order_id" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
		<div class="layui-inline fr">
          <span style="color:#CCCCCC;font-size:12px;">提示：可按回车【Enter】确认 </span><button class="layui-btn" lay-submit lay-filter="stock-defective" >确认</button>
        </div>
	</div>
	</form>
</div>
<div id="setBrokeAndNoteTpl" class="hide">
	<form class="layui-form layui-form-pane" action="{:url()}?action=addProcessCount"  method="post" id="editForm222">
	<div class="layui-form-item pt20 pl20">
		<div class="layui-inline broke_count_block" style="display:none">
			<label class="layui-form-label">报损数量</label>
			<div class="layui-input-inline">
				<input type="text" name="broke_count"  lay-verify="number|required" placeholder="输入报损数" class="layui-input broke_count_input">
			</div>
		</div>
        <div class="layui-inline process_remark_block" style="display:none">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-inline">
				<input type="text" name="process_remark" placeholder="输入备注" class="layui-input process_remark_input">
			</div>
		</div>
        <input type="hidden" class="field-id" name="process_name" value="{{d.processname}}">
        <input type="hidden" class="field-id" name="memberid" value="{{d.user_number}}">
        <input type="hidden" class="field-id" name="dataid" value="{{d.dataid}}">
		<input type="hidden" name="orderid" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
		<div class="layui-inline fr">
          <span style="color:#CCCCCC;font-size:12px;">提示：可按回车【Enter】确认 </span><button class="layui-btn" lay-submit lay-filter="setBrokeAndNote" >确认</button>
          <a href="javascript:layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
        </div>
	</div>
	</form>
</div>
<div id="salaryMonthTpl" style="display:none">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
    <div class="layui-form-item pt20 pl20 createBillTemp" style="padding-right:20px;">
    	账单工资月份：{:Form::select('billmonth',$select_month, $billmonth, '', '','lay-ignore onchange="setUrlParam(this)"')}<br />
        <div style="padding-top:20px;">
            <input type="hidden" name="order_id" value="{{ d.order_id }}">
            <input type="hidden" name="url" value="{{ d.url }}">
            <div style="text-align:center;">
              <button data-href="{:url('statementsCheck')}?action=setSalaryMonth&billmonth={:$select_month}" 
              class="layui-btn j-page-btns layui-icon confirmSubmitCreateBill" lay-submit lay-filter="confirmSubmitCreateBill" >确认提交</button>
            </div>
        </div>
    </div>
	</form>
</div>

<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/vue@3.2.26/dist/vue.global.js"></script>
<script type="text/javascript">
    //#vue_tab_content
    const allContent = {
        data() {
            return {
                statData_1:0,
            statData_2:0
        }
        }
    }
    const vm=Vue.createApp(allContent).mount('#vue_tab_content');
    layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer','laytpl','upload'], function() {
        var $ = layui.jquery;
        var table = layui.table;
		var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;
		var upload = layui.upload;
        var initialize=0,second_initialize=0,first_init=0,changetab=0;
        laydate.render({
            elem: '#create_date_range'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range').val(value);
                $('#layui-laydate1').remove();//关闭面板
            }
        });	
		laydate.render({
            elem: '#instock_date_range'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#instock_date_range').val(value);
                $('#layui-laydate2').remove();//关闭面板
            }
        });	
		
		$(document).on('scroll', function() {
			var formWidth = $('.fixed-bar').width();
			var barHeight = $('.fixed-bar-form').height();
			if ($(document).scrollTop() > 30 && window.screen.width >= 600) {
				$('.fixed-bar').css('height', barHeight);
				$('.fixed-bar .fixed-bar-form').addClass('fixed-bar-form-fixed');
				if($(".layui-table-header").length<=3){
					$(".layui-table-header").eq(0).addClass('fixed-bar-tr-header');
					$(".layui-table-tool").eq(0).addClass('fixed-bar-tr-header tools-header');
					$(".layui-table-fixed-r").find(".layui-table-header").hide();
				}
				$('.fixed-bar .fixed-bar-form').css('width', (formWidth-10)+'px');
				
				if($('.layui-close-search').length == 0) {
					$('.fixed-bar .fixed-bar-form .layui-form-item').append('<div class="layui-inline layui-close-search"><button type="button" class="layui-btn layui-btn-danger layui-close-search-btn">关闭</button></div>');
				}
			} else {
				$('.fixed-bar .fixed-bar-form').css('display', 'inherit');
				$('.fixed-bar .fixed-bar-form').removeClass('fixed-bar-form-fixed');
				$(".layui-table-tool").eq(0).removeClass('fixed-bar-tr-header tools-header');
				$(".layui-table-header").removeClass('fixed-bar-tr-header');
				$(".layui-table-fixed-r").find(".layui-table-header").show();
				$('.layui-close-search-btn').parent().remove();
			}
		});	

        window.status=0;
        window.statCli = function(status) {
            var url='{:url()}?status='+status;
            window.status=status;
            $("#hisi-table-search").attr('action',url);
            $("#seacher").click();
            changetab=1;
			//隐藏或显示每个标签卡可操作的功能  1文员2财务3复合帐单4帐单明细
			if(status==1){
				$(".office_operate").show();
				$(".other_operate").show();
				$(".finance_operate").hide();
			}else if(status==2){
				$(".finance_operate").show();
				$(".other_operate").show();
				$(".office_operate").hide();
			}else{
				$(".office_operate").hide();
				$(".finance_operate").hide();
				$(".other_operate").hide();
			}
			
        }
		
		// 工价调整
		var layerDefective = null;
		$(document).on('click','.edit-processPrice',function(){
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var ordernum=$(this).attr("ordernum");
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			var content = laytpl($('#defectiveTpl').html()).render(d);
			layerDefective = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'修改订单工价 '+ ordernum
				,content: content
			});
			$(".process_price_input").eq(1).select();
		});
		
		$(document).on('click','.show-setBrokeAndNote',function(){
			var orderId = $(this).attr('data-orderid');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var ordernum=$(this).attr("ordernum");
			var d = [];
			var dataid = $(this).attr('data-id');
			var user_name = $(this).attr('data-username');
			var user_number = $(this).attr('data-usernumber');
			var processname = $(this).attr('data-processname');
			d['user_number']=user_number;
			d['processname']=processname;
			d['dataid']=dataid;
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			console.log(json);
			$(".process_remark_block").hide();
			$(".broke_count_block").show();
			var content = laytpl($('#setBrokeAndNoteTpl').html()).render(d);
			layerDefective = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'设置报损数 '+ ordernum
				,content: content
			});
			$(".broke_count_input").eq(1).focus();
		});
		
		$(document).on('click','.show-setNoteTpl',function(){
			var orderId = $(this).attr('data-orderid');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var ordernum=$(this).attr("ordernum");
			var d = [];
			var dataid = $(this).attr('data-id');
			var user_name = $(this).attr('data-username');
			var user_number = $(this).attr('data-usernumber');
			var processname = $(this).attr('data-processname');
			d['user_number']=user_number;
			d['processname']=processname;
			d['dataid']=dataid;
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			$(".process_remark_block").show();
			$(".broke_count_block").hide();
			var content = laytpl($('#setBrokeAndNoteTpl').html()).render(d);
			layerDefective = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'设置订单备注 '+ ordernum
				,content: content
			});
			$(".broke_count_input").eq(1).val(9999);
			$(".process_remark_input").eq(1).focus();
		});
		
		$(document).on('click','.edit-paycount',function(){
			var dataid = $(this).attr('data-id');
			var user_name = $(this).attr('data-username');
			var user_number = $(this).attr('data-usernumber');
			var processname = $(this).attr('data-processname');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var ordernum=$(this).attr("ordernum");
			var d = [];
			d['pay_total']=$(this).attr("data-count");
			d['process_name']=processname;
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['id'] = dataid; d['user_name'] = user_name; d['user_number'] = user_number;
			var content = laytpl($('#changePayCountTpl').html()).render(d);
			layerPaycount = layer.open({
				type: 1
				,area: ['550px', '430px']
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'增加结算数量 '+user_name+" "+ ordernum+" "+processname +" "+$(this).attr("data-count")
				,content: content
			});
			$(".add_pay_count").eq(1).focus();
		});
		
		form.on('submit(stock-defective)', function (data) {
			//console.log(data.field);
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url,
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#defectiveTpl form')[0].reset();
	 				 layer.close(layerDefective);
					 layer.msg(res.msg, {icon: 1,time:600,end:function(){
					 	//opTable.reload();
					 }});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			
			return false;
		});

        var opTable =table.render({
            elem: '#dataTable'
            ,url: '{:url("", ["status" => $status,"process_stage" => $process_stage])}' //数据接口
            ,page: true //开启分页
            //,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,200,1000,2000]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['exports', 'print']
            ,cols: [[ //表头 var classval=parseFloat(d.caigou_unitprice) > parseFloat(d.customer_price)? 'redclass' :'';
                {type:'checkbox'}
				,{field: 'month_and_stocktime', title: '工资月份<br>/入仓日期',width:76,templet:function(d){ return d.month+"<br>"+d.store_time;}}
				,{field: 'month', title: '工资月份',width:76}
                ,{field: 'work_time', title: '完成日期<br />/扫菲日期',width:86,templet:function(d){
					 var classval=d.work_time != d.scan_date ? 'quintityToBig' :'';
					 return d.work_time+"<br><span class='"+classval+"'>"+d.scan_date+"</span>";}}
				,{field: 'user_name', title: '姓名/编号',templet:'#usernameTpl'}
                ,{field: 'factory_name', title: '工厂',width:95,templet:function(d){ return d.factory_name+"<br>"+d.group_name;}}
                ,{field: 'skuTpl', title: '订单号/SKU', templet:'#skuTpl',width:80}
                /*,{field:'pic_res',title : '图片', templet:'#picTpl',width:60}*/
                ,{field: 'quantity', title: '订单总数'}
				,{field: 'shicai_count', title: '实裁数+补片数'}
				,{field: 'jiaohuo_count', title: '车间完成',templet:function(d){ return d.jiaohuo_count;}}
				,{field: 'process_name', title: '工序'}
				//,{field: 'process_count', title: '累计加工数',templet:function(d){ return d.tot_process_quintity;}}
				,{field: 'process_quintity', title: '加工数量',width:70}
				,{field: 'last_confirm_process_price', title: '上次结算价'}
				,{field: 'process_price', title: '结算单价'}
				,{field: 'pay_quantity', title: '结算数量',templet:'#pay_quantity_tpl',style:'border-bottom:2px dotted #5FB878;'}
				,{field: 'history_pay_count', title: '累计结算',templet:'#processCountTpl'}
				/*,{field: 'demodata1', title: '结算方式'}*/
				,{field: 'store_count', title: 'MES入仓'}
				,{field: 'stock_count', title: '米莫入库<br>占用出库',templet:function(d){ return d.stock_count+"<br>"+d.available_checkout_count;}}
				,{field: 'count_diff', title: '件数差异',templet:'#countDiffTpl'}
				,{field: 'money_total', title: '结算金额'}
				,{field: 'delivery_count', title: '打包数'}
				,{field: 'broke_make_count', title: '生产报损'}
				,{field: 'broke_cost_count', title: '成本报损'}
				,{field: 'broke_diff', title: '报损差异',templet:'#brokeDiffTpl'}
				,{field: 'check_remark', title: '备注',width:100}
				,{field: 'creater_name', title: '审核人/日期',templet:function(d){ return d.check_user+d.f_check_date;}}
				,{field: 'recheck_user', title: '复审人'}
				,{field: 'pay_state', title: '状态'}
                ,{field: 'change_price', title: '操作',templet:'#buttonTpl',width:180,fixed: 'right'}
				,{field: 'recheck_action', title: '操作',templet:'#recheckActionTpl'}
            ]]
            ,done: function(res, curr, count){
                var data=res.data;
                var status=res.status;
				//设置审核标签的显示与隐藏
				if(status==1){
					$(".office_operate").show();
					$(".other_operate").show();
					$(".finance_operate").hide();$(".recheck_operate").hide();
				}else if(status==2){
					$(".finance_operate").show();
					$(".other_operate").show();
					$(".office_operate").hide();$(".recheck_operate").hide();
				}else{
					$(".office_operate").hide();
					$(".finance_operate").hide();
					$(".other_operate").hide();
					$(".recheck_operate").show();
					if(status==4) $(".recheck_operate").hide();
				}
                for (var i in data){
					//alert(data[i]['id']+'-'+data[i]['creater']);
					$(".redclass").parent().addClass("quintityToBig");
					$(".warning").parent().addClass("waring");
					$(".warning2").parent().addClass("warning3");
					//$(".warning2").parent().addClass("warning2");
					//if(data[i]['creater']>0){
						//$('#process_data_'+data[i]['id']).parent().parent().parent().addClass("people_add");
						//$(".quintityChanged").parent().addClass("changedBg");
					//}
                }
                layui.form.render();
                //设置 对账审核（2条/驳回0条）已审核（2条）复核账单（1条）已提交（0条）
				if(res.needcheckCount!='---'){
					vm.$data.statData_1=res.needcheckCount;
					vm.$data.statData_2=res.checkedCount;
					$(".reCheckCount").html(res.reCheckCount);
				}
                
                if(status==1){
                    $('table tr').each(function(i){
                        var remove_field=['recheck_action','month','process_price2','recheck_user','pay_state'];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                    $('.back').show();
                }else if(status==2){
                    $('table tr').each(function(i){
                        var remove_field=['recheck_action','month','recheck_user','pay_state'];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });				
                }else if(status==3){ //复合对帐
                    $('table tr').each(function(i){
                        var remove_field=['change_price','work_time','month_and_stocktime','quantity','shicai_count','process_name','skuTpl','process_count','last_confirm_process_price','process_price','pay_quantity','count_diff','broke_cost_count','process_quintity','broke_make_count','broke_diff'
						,'store_count','stock_count','change_price','jiaohuo_count','pic_res','history_pay_count','delivery_count','check_remark'];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                }else if(status==4){ //对帐明细-员工订单工序纬度
                    $('table tr').each(function(i){
                        var remove_field=['month','recheck_action','change_price','month'];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                };
                table.on('edit(demoEvent)', function(obj){
                    var value = obj.value //得到修改后的值
                        ,d = obj.data //得到所在行所有键值
                        ,field = obj.field; //得到字段
                    var id=d.id;

                    $.ajax({
                        type: "POST",
                        url: "{:url('editUnit')}",
                        data: "id="+d.id+"&field="+field+"&value="+value,
                        dataType:"json",
                        success: function(res){
                            if (res.code == 1) {
                                layer.msg(res.msg, {time:600,icon: 1});
                            } else {
                                layer.msg(res.msg, {icon: 2,anim: 6});
                            }
                        }
                    });
                });
            }
        });
		table.on('tool(demoEvent)', function(obj){
            var d = obj.data,field=obj.field;
            if(obj.event === 'delete'){
				if(confirm('确定要删除该加工信息吗')==false){
					return;
				}
				$.ajax({
					type: "POST",
					url: "{:url('statementsCheck')}?action=deleteProcess",
					data: "dataid=&memberid="+d.user_number+"&process_name="+d.process_name+"&orderid="+d.order_id,
					dataType:"json",
					success: function(res){
						if (res.code == 1) {
							layer.msg(res.msg, {time:600,icon: 1});
							obj.tr[0].remove();
							//opTable.reload();
						} else {
							layer.msg(res.msg, {icon: 2,anim: 6});
						}
					}
				});
				
			}
		});
		/*
         * 上传导入Excel
         */
        upload.render({
            elem: '#test8'
            ,url: "{:url('import',["process_stage" => $process_stage])}" //改成您自己的上传接口
            ,auto: false
            //,multiple: true
            ,bindAction: '#test9'
            , accept: 'file'
            ,done: function(res){
                if(res.code==2){
                    var order=res.data.order,sku=res.data.sku,size=res.data.size,existdata=res.data.existdata;
                    var content="";
                    var countOrder = order.length;
                    var countSku = sku.length;
                    var countSize = size.length;
                    content += '<tr>';
                    content += '<td>导入失败提示</td><td>';
					 for (var i in existdata){
						 content += '<span class="copy-item">' + existdata[i] + '</span> &nbsp&nbsp;';
					 }
                    content +='</td></tr>';
                    layer.open({
                        type: 1
                        ,title:'导入失败请完善'
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<table class="layui-table">'+content+'</table>'
                        ,btn: '关闭全部'
						,area: ['800px','400px']
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                          layer.closeAll();
                        }
                    });
                }else{
                    layer.msg(res.msg);
					 var existdata=res.data.existdata,success_count=res.data.success_count;
					 
					var content="";
					content += '<tr><td>成功个数</td><td>成功导入 '+success_count+'条记录</td></tr>';
                    content += '<tr>';
                    content += '<td>重复导入</td><td>';
					if(existdata.length>0){
						content +="以下重复的未做导入，如需导入请手工增加<br> "
					}
					 for (var i in existdata){
						 content += '<span class="copy-item">' + existdata[i] + '</span> &nbsp;||&nbsp; ';
					 }
                    content +='</td></tr>';
					 layer.open({
                        type: 1
                        ,title:'导入成功'
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<table class="layui-table">'+content+'</table>'
                        ,btn: '关闭全部'
						,area: ['800px','400px']
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                          layer.closeAll();
                        }
                    });
                }
            }
        });

        //导入金鹏加工单
        upload.render({
            elem: '#test10'
            ,url: "{:url('importJPprocess',["process_stage" => $process_stage])}" //改成您自己的上传接口
            ,auto: false
            //,multiple: true
            ,bindAction: '#test11'
            , accept: 'file'
            ,done: function(res){
                if(res.code==2){
                    var order=res.data.order,sku=res.data.sku,size=res.data.size,existdata=res.data.existdata;
                    var content="";
                    var countOrder = order.length;
                    var countSku = sku.length;
                    var countSize = size.length;
                    content += '<tr>';
                    content += '<td>导入失败提示</td><td>';
                    for (var i in existdata){
                        content += '<span class="copy-item">' + existdata[i] + '</span> &nbsp&nbsp;';
                    }
                    content +='</td></tr>';
                    layer.open({
                        type: 1
                        ,title:'导入失败请完善'
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<table class="layui-table">'+content+'</table>'
                        ,btn: '关闭全部'
                        ,area: ['800px','400px']
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }else{
                    layer.msg(res.msg);
                    var existdata=res.data.existdata,success_count=res.data.success_count;

                    var content="";
                    content += '<tr><td>成功个数</td><td>成功导入 '+success_count+'条记录</td></tr>';
                    content += '<tr>';
                    content += '<td>重复导入</td><td>';
                    if(existdata.length>0){
                        content +="以下重复的未做导入，如需导入请手工增加<br> "
                    }
                    for (var i in existdata){
                        content += '<span class="copy-item">' + existdata[i] + '</span> &nbsp;||&nbsp; ';
                    }
                    content +='</td></tr>';
                    layer.open({
                        type: 1
                        ,title:'导入成功'
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<table class="layui-table">'+content+'</table>'
                        ,btn: '关闭全部'
                        ,area: ['800px','400px']
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }
            }
        });

        /*//导入已结算加工单
        upload.render({
            elem: '#test12'
            ,url: "{:url('importPayedProcess',["process_stage" => $process_stage])}" //改成您自己的上传接口
            ,auto: false
            //,multiple: true
            ,bindAction: '#test13'
            , accept: 'file'
            ,done: function(res){
                console.log(res);
            }
        });*/
		
		//导入成本报损数
        upload.render({
            elem: '#test12'
            ,url: "{:url('',["action"=>'importCostBroke',"process_stage" => $process_stage])}" //改成您自己的上传接口
            ,auto: false
            //,multiple: true
            ,bindAction: '#test13'
            , accept: 'file'
            ,done: function(res){
				layer.msg(res.msg);
                console.log(res);
            }
        });
		
		var layerDefective = null;
		$(document).on('click','.createBillList',function(){
			if($(".layui-form-checked").size()<=0){
				layer.msg('请选择要操作的数据', {icon: 2,anim: 6});return;
			}
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var ordernum=$(this).attr("ordernum");
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			var content = laytpl($('#salaryMonthTpl').html()).render(d);
			layerDefective = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,area: ['450px','280px']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'设置账单所属月份'
				,content: content
			});
		});

        form.on('submit(stock-defective)', function (data) {
            console.log(data.field);
            var url = data.field.url;
            $.ajax({
                type: "POST",
                url: url,
                data: data.field,
                dataType:"json",
                success: function(res){
                    if (res.code == 1) {
                        $('#defectiveTpl form')[0].reset();
                        layer.close(layerDefective);
                        layer.msg(res.msg,{icon: 1,time:600,end:function(){
						//opTable.reload();
						}});
                    } else {
                        layer.msg(res.msg, {icon: 2,anim: 6});
                    }
                }
            });

            return false;
        });
	
		form.on('submit(setBrokeAndNote)', function (data) {
            console.log(data.field);
            var url = data.field.url;
            $.ajax({
                type: "POST",
                url: url,
                data: data.field,
                dataType:"json",
                success: function(res){
                    if (res.code == 1) {
                        $('#defectiveTpl form')[0].reset();
                        layer.close(layerDefective);
                        layer.msg(res.msg,{icon: 1,time:600,end:function(){
							opTable.reload();
						}});
                    } else {
                        layer.msg(res.msg, {icon: 2,anim: 6});
                    }
                }
            });
            return false;
        });
		window.setRemark=function(tag){
			var remark=$(tag).html();
			$(".field-check_remark").eq(1).val(remark);
		}
		window.callbackRefershQuintity = function(obj, res) {
			if (res.code == 1) layer.msg(res.msg,{icon: 1,time:600,end:function(){
					layui.layer.closeAll();
					window.reloadTable();
				}
			});
		}
		
		//设置url参数值
		window.setUrlParam=function(tabs) {
			var para_name=[$(tabs).attr('name')];
			var para_value=[$(tabs).val()];
			
			//para_name, para_value
			var oUrl = $(".confirmSubmitCreateBill").eq(1).attr("data-href").toString();
			for(var i=0;i<para_name.length;i++)
			{
				var re=eval('/('+ para_name[i]+'=)([^&]*)/gi');
				oUrl= oUrl.replace(re,para_name[i]+'='+para_value[i]);
			}
			$(".confirmSubmitCreateBill").eq(1).attr("data-href",oUrl);
		}
		
		$(document).on('click','.confirmSubmitCreateBill',function(){
			layer.close(layerDefective);
		});
		
		
		// 刷新当前页
        window.reloadTable = function () {
            var that = $("#hisi-table-search-optable"),
                arr = that.serializeArray(),
                where = new Array(),
                dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
                currPage = $(".layui-laypage-em").next().html()
                options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
            for(var i in arr) {
                where[arr[i].name] = arr[i].value;
            }

            options.url = that.attr('action');
            options.where = where;

            opTable.reload(options);
            return false;
        }
    });

</script>